<!--
 * @Author: jinjing
 * @Date: 2024-11-23
 * @Description: 基金日收益率标准差。
 -->
<template>
  <div class="content">
    <el-table :data="tableData">
      <!-- <el-table-column label="基金代码" prop="ticker"></el-table-column>
      <el-table-column label="2014" prop="2014"></el-table-column> -->
      <el-table-column v-for="column in columns" :key="column.prop" :prop="column.prop" :label="column.label">
        <template #default="{ row }">{{ row[column.prop] || '--' }}</template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { getNavData } from '../duckdb';

const tableData = ref([])
const columns = ref([{
  label: '基金代码',
  prop: 'ticker'
}])
const getData = async () => {
    let sql = "CREATE TABLE temp_ans_data AS SELECT ticker, YEAR(dt) AS year, STDDEV(chg) AS std_dev_chg FROM fund_nav WHERE YEAR(dt) >= 2014 GROUP BY  ticker, YEAR(dt) ORDER BY  ticker, YEAR(dt); " +
    "SELECT * FROM fund_nav PIVOT (STDDEV(chg) FOR YEAR(dt) IN (2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024) GROUP BY ticker);"
    // console.log(sql)
    let ans = await getNavData(sql)
    // console.log(ans)
    tableData.value = ans
    Object.keys(tableData.value[0]).forEach(item => {
      if (item !== 'ticker') {
        columns.value.push({label: item, prop: item})
      }
    })
    // console.log(columns.value)
}
getData()
</script>

<style>

</style>